# _*_ coding:utf-8 _*_
from django.shortcuts import render

from  .models import UserMessage
# Create your views here.


def getform(request):
    # 传递数据到html
    message = None
    all_messages = UserMessage.objects.filter(name='55')
    if all_messages:
        message = all_messages[0]

    # 传入html的值名称叫做my_message
    return  render(request, 'message_form.html',{
        'my_message':message
    })

    # 所有数据
    # all_messages = UserMessage.objects

    # 删除数据
    # all_messages = UserMessage.objects.filter(name='jack', address='bj')
    # for message in all_messages:
    #     message.delete()


    # 查询数据
    # all_messages = UserMessage.objects.filter(name='jack', address='bj')
    # for message in all_messages:
    #     print message.name

    # 添加数据
    # user_message = UserMessage()
    # user_message.name = 'joy'
    # user_message.message = 'welcome to friends'
    # user_message.address = 'new york'
    # user_message.email = 'joy@gmail.com'
    # user_message.object_id = '2'
    # user_message.save()


    # 从request中取值
    # if request.method == 'POST':
    #     name = request.POST.get('name', '')
    #     message = request.POST.get('message', '')
    #     address = request.POST.get('address', '')
    #     email = request.POST.get('email', '')
    #     user_message = UserMessage()
    #     user_message.name = name
    #     user_message.message = message
    #     user_message.address = address
    #     user_message.email = email
    #     user_message.object_id = '3'
    #     user_message.save()
    #
    # return render(request, 'message_form.html')